name: Build macOS Distributable

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: macos-latest
    
    steps:
    - uses: actions/checkout@v2
    - name: Fetch entire repository
      run: git fetch --prune --unshallow
    - name: Make
      run: make staticbindist
    - name: Determine version
      id: get_version
      run: |
        OPENMSX_MAJOR_VERSION=`python3 build/version.py`
        OPENMSX_BUILD_REVISION=`fgrep "Revision string:" derived/version.log | sed -e "s/.*: //"`
        OPENMSX_VERSION=$OPENMSX_MAJOR_VERSION-$OPENMSX_BUILD_REVISION
        echo ::set-output name=OPENMSX_VERSION::$OPENMSX_VERSION
    - name: Rename redistributable dmg
      run: |
        cd derived/x86_64-darwin-opt-3rd
        mv openmsx-${{ steps.get_version.outputs.OPENMSX_VERSION }}-mac-x86_64-bin.dmg openmsx-${{ steps.get_version.outputs.OPENMSX_VERSION }}-x86_64-darwin-opt-3rd.dmg
    - name: Upload redistributable dmg
      uses: actions/upload-artifact@v1
      with:
        name: openmsx-${{ steps.get_version.outputs.OPENMSX_VERSION }}-x86_64-darwin-opt-3rd.dmg
        path: derived/x86_64-darwin-opt-3rd/openmsx-${{ steps.get_version.outputs.OPENMSX_VERSION }}-x86_64-darwin-opt-3rd.dmg
